package com.woniu.user.service.consumer;

import com.woniu.user.service.UserVipRelationService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;


@Component
@RocketMQMessageListener(topic = "lxlg-order-payok",consumerGroup = "lxlg-order-payok")
public class VipPayOrderSuccessConsuer implements RocketMQListener<String>{

	@Resource
	private UserVipRelationService userVipRelationService;
	@Resource
	private StringRedisTemplate srt;
	
	@Override
	public void onMessage(String message) {
		String state = srt.opsForValue().get("pay:success:state:"+message);
		if(state == null || !state.equals("1")) {
			System.out.println("执行支付成功逻辑");
			userVipRelationService.setPayOk(message);
			srt.opsForValue().setIfAbsent("pay:success:state:"+message, "1", 10, TimeUnit.MINUTES);
		}
		
	}

} 
